home *** CD-ROM | disk | FTP | other *** search
- /*
- Color Window Demonstration Program
- By: Jim Griffin
- Indianapolis, IN
- IJDG400 @ Indycms.bitnet.edu
- JimGriffin on America On Line
-
- Copyright © 1990 by Jim Griffin
-
- This program may not be sold or given away for profit.
- Feel free to distribute the program and source code among your friends,
- but all files must be included in the exchange.
- Keep all the files together.
- All rights reserved.
-
-
-
- I wrote this program to teach myself about intricacies of creating color windows, and color controls.
- I don't claim that this program demonstrates the best method of creating and displaying
- color windows merely that this is one of the ways. Feel free to use the knowledge
- you learn here in other programs you may write. My only desire is that you will
- release your code so that others may also gain new knowledge in programing Macintosh
- computers.
-
- To create this program I made extensive modifications to the code from
- the "ShowOff" source code in the Developer's Source Code library that
- is in America Online.
-
-
- NOTE: I assume that you will have a copy of Inside Macintosh Vols 1 thru 5 handy.
- If not then you might have difficulty understanding some of the color
- routines such as GetColor();, GetAuxWin(aWindow, &some_new_colors);, and
- all the rest.
- I also assume that you will understand C statements that look like
-
- (**(**some_new_colors).awCTable).ctTable[0].value = 0;
-
- If the above statement makes your eyes cross, then perhaps this program
- isn't for you. On the other hand if you want to learn how use statements
- like that then you should try to read the program.
- */
-
- /* WARNING: Inside Mac Vol 5 document bug!
- Inside Mac Vol 5 on page 207 defines GetAuxWin as returning a CTabHandle,
- This is wrong, it really returns an AuxWinHandle!!!! this drove me crazy for
- an hour before I realized that it didn't make since for GetAuxWin to return
- a CTabHandle. It made more sense for it to return an AuxWinHandle. (Note
- the AuxWin in both words) Some quick experimenting with the Think C
- source Code Debugger proved this to be correct!
- P.S. If you believe Inside Mac and treat GetAuxWin as returning a CTabHandle
- you will notice that your program will do strange things and then
- really bomb!
- */
-
-
- #include "my color.h"
-
- main() /*main program*/
- {
- CWindowPtr who_is_in_front;
-
- init_color_demo(); /* initialize the Managers, prepare for program execution */
- OpenWindow(); /*start with one open window*/
-
- /* Main event loop */
- do
- {
- SystemTask();
- who_is_in_front = (CWindowPtr)FrontWindow();
- if (who_is_in_front != nil)
- if ((*(CWindowPeek)who_is_in_front).windowKind >= 0)
- FixCursor();
-
- if (!menusOK && (who_is_in_front == nil))
- {
- DisableItem (myMenus [fileM], closeItem);
- DisableItem (myMenus [editM], 0);
- menusOK = true;
- }
- if (textH != nil)
- TEIdle(textH);
- if (GetNextEvent(everyEvent,&myEvent))
- switch (myEvent.what)
- {
-
- case mouseDown:
- do_mouse_down(&myEvent);
- break;
- case keyDown:
- case autoKey:
- if ((myEvent.modifiers & cmdKey) != 0)
- DoCommand(MenuKey(myEvent.message & charCodeMask));
- else TEKey((char)(myEvent.message & charCodeMask),textH);
- break;
-
- case activateEvt:
- do_activate(&myEvent);
- break;
-
- case updateEvt:
- do_update(&myEvent);
- break;
-
- } /*switch myEvent.what*/
-
- }
- while (!doneFlag);
-
- return;
- } /*end of the main program modual*/
-
-
-
- FixCursor() /* make the cursor an I-Beam when over the content of our active window */
- /* else make the cursor an Arrow */
- {
- Point mouseLoc;
- Rect test_rect;
-
- GetMouse (&mouseLoc);
- test_rect = thePort->portRect;
- test_rect.right = test_rect.right - BAR_WIDTH; /* don't forget about the scroll bars */
- test_rect.bottom = test_rect.bottom - BAR_WIDTH;
-
- if (PtInRect (mouseLoc, &test_rect))
- SetCursor(*(GetCursor(iBeamCursor)));
- else
- SetCursor(&arrow);
- }
-
-